var should = require('should');
var mailHandler = require('../../../app/servers/user/handler/mailHandler');
var mailModel = require('../../../app/models/mailModel');
var config = require('../../config');

suite('测试mailHandler', function () {
    var mail_id = 0;
    suite('set', function () {
        setup(function (done) {
            mailModel.getByRoleId(config.role_id, function (err, mail_model) {
                var mail_title = '系统';
                var mail_content = '测试';
                var mail_reward_list = [
                    {
                        reward: 0,
                        reward_type: 2,
                        reward_value: 0,
                        reward_num: 100
                    },
                    {
                        reward: 0,
                        reward_type: 1,
                        reward_value: 0,
                        reward_num: 1000
                    },
                    {
                        reward: config.equip_id,
                        reward_type: 5,
                        reward_value: 0,
                        reward_num: 1
                    }
                ];
                var add_mail_item = mail_model.addMail(mail_title, mail_content, mail_reward_list);
                mail_model.toJSON();
                mail_model.save(done);
                if (!!add_mail_item) {
                    mail_id = add_mail_item.id;
                }
            });
        });

        test('设置邮件状态', function (done) {
            var msg = {};
            var session = {};
            session.uid = config.role_id;

            var mail_handler = new mailHandler();
            mail_handler.setMailStatus(msg, session, function (err, res) {
                done();
            });
        });

        test('设置邮件状态', function (done) {
            var msg = {
                mail_id: 10001
            };
            var session = {};
            session.uid = config.role_id;

            var mail_handler = new mailHandler();
            mail_handler.setMailStatus(msg, session, function (err, res) {
                done();
            });
        });

        test('获取奖励1', function (done) {
            var msg = {};
            var session = {};
            session.uid = config.role_id;

            var mail_handler = new mailHandler();
            mail_handler.reward(msg, session, function (err, res) {
                done();
            });
        });

        test('获取奖励2', function (done) {
            var msg = {
                mail_id: mail_id
            };
            var session = {};
            session.uid = config.role_id;

            var mail_handler = new mailHandler();
            mail_handler.reward(msg, session, function (err, res) {
                done();
            });
        });

        test('获取奖励', function (done) {
            var msg = {};
            var session = {};
            session.uid = config.role_id;

            var mail_handler = new mailHandler();
            mail_handler.allReward(msg, session, function (err, res) {
                done();
            });
        });
    });
});
